//
//  PPTimelinePictureDescriptionView.m
//  pickpic
//
//  Created by Jinxiao on 10/6/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPTimelinePictureDescriptionView.h"

@interface PPTimelinePictureDescriptionView ()
@property (readwrite, nonatomic, strong) UILabel *label;
@end

@implementation PPTimelinePictureDescriptionView

- (instancetype)init {
    self = [super init];

    self.backgroundColor = [UIColor colorWithRGBHex:0x00 alpha:0.8];

    _label = [[UILabel alloc] init];
    _label.numberOfLines = 0;
    _label.textAlignment = NSTextAlignmentLeft;
    _label.lineBreakMode = NSLineBreakByWordWrapping;
    _label.font = [UIFont systemFontOfSize:13];
    _label.textColor = [UIColor whiteColor];
    [self addSubview:_label];

    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(6, 12, 15, 12));
    }];

    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    _label.frame = CGRectMake(12, 6, self.width - 24, self.height - 21);
}

- (void)setDesc:(NSString *)desc {
    _desc = desc;

    if(_desc.length == 0) {
        self.hidden = YES;
    } else {
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.alignment = NSTextAlignmentLeft;
        paragraph.lineBreakMode = NSLineBreakByWordWrapping;

        _label.attributedText = [[NSAttributedString alloc] initWithString:_desc attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13], NSParagraphStyleAttributeName: paragraph}];
        
        self.hidden = NO;
    }

    [self setNeedsLayout];
}

@end
